package com.example.administrator.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TwoActivity extends AppCompatActivity {

    private Button finishBtn;
    private EditText usernameEd;
    private EditText scoreEd;
    private EditText ispassedEd;
    private Button startActivityBtn;
    private String studentName;
    private String scoreStr;
    private String ispassedStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        initView();

        initEvent();
    }
    private void initView(){
        finishBtn = findViewById(R.id.activity_finish_btn);
        usernameEd = findViewById(R.id.username_et);
        scoreEd = findViewById(R.id.score_et);
        ispassedEd = findViewById(R.id.ispassed_et);
        startActivityBtn = findViewById(R.id.startactivity_btn);
    }
    private void initData(){
        studentName = usernameEd.getText().toString()+"";
        scoreStr = scoreEd.getText()+"";
        ispassedStr = ispassedEd.getText()+"";
    }
    private void initEvent(){
        finishBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();//关闭当前的Activity
            }
        });
        startActivityBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initData();
                //创建intent对象
                int score=Integer.parseInt(scoreStr);
                boolean ispassed=Boolean.parseBoolean(ispassedStr);

                Intent intent=new Intent(TwoActivity.this,ThreeAtivity.class);
//                intent.putExtra("studentName",studentName);
//                intent.putExtra("score",score);
//                intent.putExtra("ispassed",ispassed);
                //实例化bundle
                Bundle bundle=new Bundle();
                bundle.putString("studenName",studentName);
                bundle.putInt("sroce",score);
                bundle.putBoolean("ispassed",ispassed);
                intent.putExtras(bundle);//将bundle存放在intent中携带到目标activity
                Toast.makeText(TwoActivity.this,"姓名:"+studentName,Toast.LENGTH_SHORT).show();
                startActivity(intent);
            }
        });
    }

}
